#/!/bin/bash
#镜像保留的个数
image_number="2"
#####################################################################
mas_sla=$1
commds=$2
basepath=$(cd `dirname $0`; pwd)
envs=""
registry="docker_test"

source ${basepath}/conf/log.sh
source ${basepath}/conf/base_container.sh


#Judging environment according to IP segment
#macth_envs

#Execution script

if [[ $# -lt 3 ]] || [[ "$1" != "master"  ]] || \
   [[ "$2" != "run" && "$2" != "update" && "$2" != "start" && "$2" != "stop" && "$2" != "del" && "$2" != "status" && "$2" != "restart" ]];
then
  usage && exit 0
fi

images_list(){
  lists_bus=`docker images|grep "${registry}"|awk '{print $1}'|awk -F '/' '{print $2}'|awk '!a[$0]++'`
}

images_list

if [[ $# -eq 3 && "$3" = "automatic" ]];then
      check "$lists_bus" 
else 
  bus_list=${@:3}; 
  if [ "$2" = "start" -o "$2" = "stop" -o "$2" = "del" ];then
    for i in $bus_list; do  container_sh  "$2"; done
  elif [ "$2" = "restart" ];then
     for i in $bus_list; do  container_sh "stop";container_sh  "start"; done
  else
    usage && exit 0
    fi
fi
